package com.test1230am;

public class Test15 {
    public static void main(String[] args) {
        // (15)定义实现m方法：求数组中最小的偶数
        int[] arr = {1,2,3,4,5};
        int min = m(arr);
        System.out.println(min);
    }
    public static int m(int[] arr){
        int count =0;
        for(int i=0;i<arr.length;i++){
            if(arr[i]%2==0){
               count++;
            }
        }
        int[] newArr = new int[count];
        int index = 0;
        for(int i=0;i<arr.length;i++){
            if(arr[i]%2==0){
                newArr[index] =arr[i];
                index++;
            }
        }
        int min = newArr[0];
        for(int j=1;j<newArr.length;j++){
            if(min>arr[j]){
                min=arr[j];
            }
        }
        return min;
    }
}
